@echo off
echo ========================================================
echo Last War All-in-One Server Startup Script
echo ========================================================

REM 设置Java环境
set JAVA_HOME=D:\soft\green\jdk\konaJdk\TencentKona-21.0.8.b1
set PATH=%JAVA_HOME%\bin;%PATH%

REM 检查Java版本
java -version >nul 2>&1
if errorlevel 1 (
    echo ERROR: Java 21 is required but not found!
    echo Please install Java 21 and set JAVA_HOME environment variable
    pause
    exit /b 1
)

echo Java version check passed...

REM 检查JAR文件是否存在
if not exist "target\all-in-one-1.0.0.jar" (
    echo ERROR: all-in-one JAR file not found!
    echo Please build the project first: mvn clean package -DskipTests
    pause
    exit /b 1
)

echo Starting Last War All-in-One Server...
echo.
echo Server Ports Configuration:
echo • Login Server:    127.0.0.1:30001 (Netty) / 8080 (HTTP)
echo • Gate Server:     127.0.0.1:40001 (Netty) / 8082 (HTTP)
echo • Scene Server:   127.0.0.1:50001 (Netty) / 8083 (HTTP)
echo • Central Server: 127.0.0.1:60001 (Netty) / 8084 (HTTP)
echo • Balance Server: 127.0.0.1:70001 (Netty) / 8085 (HTTP)
echo • All-in-One HTTP: 127.0.0.1:8081 (HTTP)
echo.

REM 启动参数
set JAVA_OPTS=-Xmx2g -Xms1g -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -XX:+UseStringDeduplication
set SPRING_PROFILES_ACTIVE=%1
if "%SPRING_PROFILES_ACTIVE%"=="" set SPRING_PROFILES_ACTIVE=dev

echo Starting with profile: %SPRING_PROFILES_ACTIVE%
echo Java Options: %JAVA_OPTS%
echo.

REM 启动服务器
java %JAVA_OPTS% -Dspring.profiles.active=%SPRING_PROFILES_ACTIVE% -jar target\all-in-one-1.0.0.jar

echo.
echo Server has been stopped.
pause